package objects;



import containers.Canvas;
import containers.Simulation;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.geom.Point2D;


/**
 * A Muscle is a spring with a time-varying rest length.
 * A sine formula controls the oscillation.
 * 
 * @author rwb10 & sab60
 * 
 */
public class Muscle extends Spring {
    /**
     * Size of the small muscle midpoint circles.
     */
    private static int ourMuscleSize = 4;
    private double myAmplitude;
    private long myCounter;
    private double myCurrentLength;


    /**
     * 
     * @param start The first Mass connected.
     * @param end The second Mass connected.
     * @param length Rest length of muscle.
     * @param kVal Spring constant.
     * @param amplitude Amplitude of change in rest length.
     */
    public Muscle (Mass start, Mass end, double length, double kVal,
            double amplitude) {

        super(start, end, length, kVal);
        myAmplitude = amplitude;
    }

    @Override
    public void update (Simulation canvas, double dt) {
        // change current length b/c muscle.
        myCounter += dt;
        myCurrentLength = getMyLength() + (myAmplitude * Math.cos(Math.toRadians(myCounter)));

        // call update() of Spring to apply hooke's law
        // with the updated rest length
        super.update(canvas, dt);
    }

    @Override
    protected double restDistance() {
        return myCurrentLength - currentLength();
    }

    @Override
    public void paint (Graphics2D pen) {
        // draw a black dot in the midpoint of the muscle to
        // differentiate it from regular springs
        Point2D mp = Force.midpoint(getMyStart().getCenter(), getMyEnd().getCenter());
        Canvas.paintCircle(pen, mp, ourMuscleSize, Color.BLACK);

        // call paint method of Spring
        super.paint(pen);
    }

}
